# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import sys
import pymysql
import hashlib
from scrapy.exceptions import DropItem
from scrapy.http import Request
class NjxinfangPipeline(object):
    def __init__(self):
#数据库连接信息
        self.connect = pymysql.connect(
            host='10.0.20.137',
            user='master',
            port=3306,
            passwd='master',
            db='ljxf',
            charset='utf8'
        )
        self.cursor = self.connect.cursor()
#数据库插入语句函数
    def process_item(self, item, spider):
        insert_sql = "INSERT INTO njxinfang(housename,totalprice,unitprice,constructarea,station,shoukuang,mode) VALUES(%s,%s,%s,%s,%s,%s,%s)"
        try:
            self.cursor.execute(insert_sql,(
                item['housename'], item['totalprice'], item['unitprice'], item['constructarea'], item['station'],
                item['condition'], item['mode']))
            self.connect.commit()
        except Exception as e:
            print(e.args)
            return False

#数据库关闭函数
    def close_spider(self, spider):
        self.cursor.close()
        self.connect.close()

class BjxinfangPipeline(object):
    def __init__(self):
#数据库连接信息
        self.connect = pymysql.connect(
            host='10.0.20.137',
            user='master',
            port=3306,
            passwd='master',
            db='ljxf',
            charset='utf8'
        )
        self.cursor = self.connect.cursor()
#数据库插入语句函数
    def process_item(self, item, spider):
        insert_sql = "INSERT INTO bjxinfang(housename,totalprice,unitprice,constructarea,station,shoukuang,mode) VALUES(%s,%s,%s,%s,%s,%s,%s)"
        try:
            self.cursor.execute(insert_sql,(
                item['housename'], item['totalprice'], item['unitprice'], item['constructarea'], item['station'],
                item['condition'], item['mode']))
            self.connect.commit()
        except Exception as e:
            print(e.args)
            return False

#数据库关闭函数
    def close_spider(self, spider):
        self.cursor.close()
        self.connect.close()

class ShxinfangPipeline(object):
    def __init__(self):
#数据库连接信息
        self.connect = pymysql.connect(
            host='10.0.20.137',
            user='master',
            port=3306,
            passwd='master',
            db='ljxf',
            charset='utf8'
        )
        self.cursor = self.connect.cursor()
#数据库插入语句函数
    def process_item(self, item, spider):
        insert_sql = "INSERT INTO shxinfang(housename,totalprice,unitprice,constructarea,station,shoukuang,mode) VALUES(%s,%s,%s,%s,%s,%s,%s)"
        try:
            self.cursor.execute(insert_sql,(
                item['housename'], item['totalprice'], item['unitprice'], item['constructarea'], item['station'],
                item['condition'], item['mode']))
            self.connect.commit()
        except Exception as e:
            print(e.args)
            return False

#数据库关闭函数
    def close_spider(self, spider):
        self.cursor.close()
        self.connect.close()